package com.bdqn.vueboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.vueboot.entity.Furniture;
import com.bdqn.vueboot.entity.Mail;
import com.bdqn.vueboot.mapper.FurnitureMapper;
import com.bdqn.vueboot.service.FurnitureServices;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Service
public class FurnitureServiceImpl extends ServiceImpl<FurnitureMapper, Furniture>
        implements FurnitureServices {
    @Resource
    FurnitureMapper furnitureMapper;

    @Override
    public IPage<Furniture> queryFurnitureLitBiz(Integer furnitureService, String furnitureAddress, Integer furnitureUsrid, Integer furnitureStaticid, String creationTime, Integer indexPage, Integer limit) {
        Page page = new Page(indexPage, limit);
        return furnitureMapper.queryFurnitureList(furnitureService, furnitureAddress, furnitureUsrid, furnitureStaticid, creationTime, page);
    }

    @Override
    public int seva(Furniture furniture) {
        if (furniture.getFurnitureId() == null || furniture.getFurnitureId() == 0) {
            return furnitureMapper.insert(furniture);
        } else {
            return furnitureMapper.updateById(furniture);
        }
    }

    @Override
    public int delFurniture(Long furnitureId, Long isDel) {
        Furniture furniture = new Furniture();
        furniture.setFurnitureId(furnitureId);
        furniture.setIsDel(isDel);
        return furnitureMapper.updateById(furniture);
    }

    @Override
    public int sevaAudit(Long furnitureStaticId, Long furnitureId) {
        UpdateWrapper<Furniture> updateWrapper = new UpdateWrapper();
        updateWrapper.eq("furniture_Id", furnitureId);
        Furniture furniture1 = new Furniture();
        furniture1.setFurnitureStaticid(furnitureStaticId);
        return furnitureMapper.update(furniture1, updateWrapper);
    }

    @Override
    public IPage<Furniture> allIsNullFurniture(Integer indexPage, Integer limit) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.isNull("furniture_StaticId");
        queryWrapper.eq("isDel", 0);
        Page page = new Page(indexPage, limit);
        return furnitureMapper.selectPage(page, queryWrapper);

    }
}




